<?php
/**
 * Created by jinqiang on 2025/3/20 14:02.
 * Copyright (c) 2025, Your Company. All rights reserved.
 */


namespace App\Http\Controllers\Banshi;


use App\Http\Controllers\Controller;
use App\Http\Repository\CommonRepository;
use App\Http\Services\Banshi\InformationService;
use Illuminate\Http\Request;

class InformationController extends Controller
{
    //获取目标群体列表
    public function targetList(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'page' => 'required',
            'limit' => 'required'
        ]);
        $param = $request->all();
        $res = $informationService->targetSearch($param);
        return result($res);
    }

    //保存目标群体
    public function targetSave(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'number' => 'required',
            'name' => 'required'
        ]);
        $param = $request->all();
        $res = $informationService->targetSave($param);
        return $res['code'] === 0 ? success("保存成功") : error($res['msg'], $res);
    }

    //获取季节列表
    public function seasonList(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'page' => 'required',
            'limit' => 'required'
        ]);
        $param = $request->all();
        $res = $informationService->seasonSearch($param);
        return result($res);
    }

    //保存季节
    public function seasonSave(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'number' => 'required',
            'name' => 'required'
        ]);
        $param = $request->all();
        $res = $informationService->seasonSave($param);
        return $res['code'] === 0 ? success("保存成功") : error($res['msg'], $res);
    }

    //获取品牌列表
    public function brandList(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'page' => 'required',
            'limit' => 'required'
        ]);
        $param = $request->all();
        $res = $informationService->brandSearch($param);
        return result($res);
    }

    //保存品牌
    public function brandSave(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'number' => 'required',
            'name' => 'required'
        ]);
        $param = $request->all();
        $res = $informationService->brandSave($param);
        return $res['code'] === 0 ? success("保存成功") : error($res['msg'], $res);
    }

    //成品颜色列表
    public function colourList(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'page' => 'required',
            'limit' => 'required'
        ]);
        $param = $request->all();
        $res = $informationService->colourSearch($param);
        return result($res);
    }

    //成品颜色状态设置
    public function colourStateSet(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'id' => 'required',
            'state' => 'required'
        ]);
        $param = $request->all();
        $res = $informationService->coloreStateSet((Int)$param['id'], (Int)$param['state']);
        return $res['code'] === 0 ? success("成品颜色状态启用成功") : error("成品颜色状态启用失败", $res);
    }

    //成品颜色保存
    public function colourSave(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'name' => 'required'
        ]);
        $param = $request->all();
        $res = $informationService->colourSave($param);
        return $res['code'] === 0 ? success("保存成功") : error($res['msg'], $res);
    }

    //品类列表
    public function classList(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'page' => 'required',
            'limit' => 'required'
        ]);
        $param = $request->all();
        $res = $informationService->classSearch($param);
        return result($res);
    }

    //品类保存
    public function classSave(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'number' => 'required',
            'name' => 'required'
        ]);
        $param = $request->all();
        $res = $informationService->classSave($param);
        return $res['code'] === 0 ? success("保存成功") : error($res['msg'], $res);
    }

    //设计分类列表
    public function categoryList(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'page' => 'required',
            'limit' => 'required'
        ]);
        $param = $request->all();
        $res = $informationService->categorySearch($param);
        return result($res);
    }

    //设计分类保存
    public function categorySave(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'number' => 'required',
            'name' => 'required'
        ]);
        $param = $request->all();
        $res = $informationService->categorySave($param);
        return $res['code'] === 0 ? success("保存成功") : error($res['msg'], $res);
    }

    //设计分类删除
    public function categoryDel(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'id' => 'required',
        ]);
        $param = $request->all();
        $res = $informationService->categoryDel((Int)$param['id']);
        return $res['code'] === 0 ? success("删除成功") : error($res['msg'], $res);
    }

    //设计类型列表
    public function typeList(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'page' => 'required',
            'limit' => 'required'
        ]);
        $param = $request->all();
        $res = $informationService->typeSearch($param);
        return result($res);
    }

    //设计类型保存
    public function typeSave(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'number' => 'required',
            'name' => 'required'
        ]);
        $param = $request->all();
        $res = $informationService->typeSave($param);
        return $res['code'] === 0 ? success("保存成功") : error($res['msg'], $res);
    }

    //文化属性列表
    public function cultureList(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'page' => 'required',
            'limit' => 'required'
        ]);
        $param = $request->all();
        $res = $informationService->cultureSearch($param);
        return result($res);
    }

    //文化属性保存
    public function cultureSave(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'number' => 'required',
            'name' => 'required'
        ]);
        $param = $request->all();
        $res = $informationService->cultureSave($param);
        return $res['code'] === 0 ? success("保存成功") : error($res['msg'], $res);
    }

    //商品属性列表
    public function goodsList(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'page' => 'required',
            'limit' => 'required'
        ]);
        $param = $request->all();
        $res = $informationService->goodsSearch($param);
        return result($res);
    }

    //商品属性保存
    public function goodsSave(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'name' => 'required'
        ]);
        $param = $request->all();
        $res = $informationService->goodsSave($param);
        return $res['code'] === 0 ? success("保存成功") : error($res['msg'], $res);
    }

    //商品属性删除
    public function goodsDel(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'id' => 'required',
        ]);
        $param = $request->all();
        $res = $informationService->goodsDel((Int)$param['id']);
        return $res['code'] === 0 ? success("删除成功") : error($res['msg'], $res);
    }

    //套装列表
    public function suitList(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'page' => 'required',
            'limit' => 'required'
        ]);
        $param = $request->all();
        $res = $informationService->suitSearch($param);
        return result($res);
    }

    //套装保存
    public function suitSave(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'name' => 'required'
        ]);
        $param = $request->all();
        $res = $informationService->suitSave($param);
        return $res['code'] === 0 ? success("保存成功") : error($res['msg'], $res);
    }

    //套装删除
    public function suitDel(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'id' => 'required',
        ]);
        $param = $request->all();
        $res = $informationService->suitDel((Int)$param['id']);
        return $res['code'] === 0 ? success("删除成功") : error($res['msg'], $res);
    }

    //核价类型列表
    public function ptypeList(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'page' => 'required',
            'limit' => 'required'
        ]);
        $param = $request->all();
        $res = $informationService->ptypeSearch($param);
        return result($res);
    }

    //核价类型保存
    public function ptypeSave(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'name' => 'required'
        ]);
        $param = $request->all();
        $res = $informationService->ptypeSave($param);
        return $res['code'] === 0 ? success("保存成功") : error($res['msg'], $res);
    }

    //核价类型删除
    public function ptypeDel(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'id' => 'required',
        ]);
        $param = $request->all();
        $res = $informationService->ptypeDel((Int)$param['id']);
        return $res['code'] === 0 ? success("删除成功") : error($res['msg'], $res);
    }

    //核价用途列表
    public function puseList(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'page' => 'required',
            'limit' => 'required'
        ]);
        $param = $request->all();
        $res = $informationService->puseSearch($param);
        return result($res);
    }

    //核价用途保存
    public function puseSave(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'name' => 'required'
        ]);
        $param = $request->all();
        $res = $informationService->puseSave($param);
        return $res['code'] === 0 ? success("保存成功") : error($res['msg'], $res);
    }

    //核价用途删除
    public function puseDel(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'id' => 'required',
        ]);
        $param = $request->all();
        $res = $informationService->puseDel((Int)$param['id']);
        return $res['code'] === 0 ? success("删除成功") : error($res['msg'], $res);
    }

    //工艺类型列表
    public function artsList(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'page' => 'required',
            'limit' => 'required'
        ]);
        $param = $request->all();
        $res = $informationService->artsSearch($param);
        return result($res);
    }

    //工艺类型保存
    public function artsSave(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'name' => 'required'
        ]);
        $param = $request->all();
        $res = $informationService->artsSave($param);
        return $res['code'] === 0 ? success("保存成功") : error($res['msg'], $res);
    }

    //工艺类型删除
    public function artsDel(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'id' => 'required',
        ]);
        $param = $request->all();
        $res = $informationService->artsDel((Int)$param['id']);
        return $res['code'] === 0 ? success("删除成功") : error($res['msg'], $res);
    }

    //样衣工序列表
    public function sampleList(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'page' => 'required',
            'limit' => 'required'
        ]);
        $param = $request->all();
        $res = $informationService->sampleSearch($param);
        return result($res);
    }

    //样衣工序保存
    public function sampleSave(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'name' => 'required'
        ]);
        $param = $request->all();
        $res = $informationService->sampleSave($param);
        return $res['code'] === 0 ? success("保存成功") : error($res['msg'], $res);
    }

    //样衣工序删除
    public function sampleDel(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'id' => 'required',
        ]);
        $param = $request->all();
        $res = $informationService->sampleDel((Int)$param['id']);
        return $res['code'] === 0 ? success("删除成功") : error($res['msg'], $res);
    }

    //物料单位列表
    public function munitList(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'page' => 'required',
            'limit' => 'required'
        ]);
        $param = $request->all();
        $res = $informationService->munitSearch($param);
        return result($res);
    }

    //物料单位保存
    public function munitSave(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'name' => 'required'
        ]);
        $param = $request->all();
        $res = $informationService->munitSave($param);
        return $res['code'] === 0 ? success("保存成功") : error($res['msg'], $res);
    }

    //物料单位删除
    public function munitDel(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'id' => 'required',
        ]);
        $param = $request->all();
        $res = $informationService->munitDel((Int)$param['id']);
        return $res['code'] === 0 ? success("删除成功") : error($res['msg'], $res);
    }

    //物料属性
    public function attribute()
    {
        $attribute = json_decode(CommonRepository::ATTRIBUTE, true);
        $attributeDetail = json_decode(CommonRepository::ATTRIBUTE_DETAIL, true);
        foreach ($attribute as &$item){
            $item['detail'] = $attributeDetail[$item['id']];
        }
        unset($item);
        return result($attribute);
    }

    //物料分类列表
    public function mcategoryList(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'page' => 'required',
            'limit' => 'required',
        ]);
        $param = $request->all();
        $res = $informationService->mcategorySearch($param);
        return result($res);
    }

    //物料分类保存
    public function mcategorySave(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'name' => 'required'
        ]);
        $param = $request->all();
        $res = $informationService->mcategorySave($param);
        return $res['code'] === 0 ? success("保存成功") : error($res['msg'], $res);
    }

    //物料分类删除
    public function mcategoryDel(Request $request, InformationService $informationService)
    {
        $this->validate($request, [
            'id' => 'required',
        ]);
        $param = $request->all();
        $res = $informationService->mcategoryDel((Int)$param['id']);
        return $res['code'] === 0 ? success("删除成功") : error($res['msg'], $res);
    }
}
